package com.feign.util;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by dell on 2016/9/29.
 */
public class SSOUtil {

    public static final String KEY_HEAD="SSO_KEY_";

    public static final Long KEY_EXPIRE=60*30L;    //30分钟过期

    //获得客户端真实IP地址的方法
    public static String getIpAddr(HttpServletRequest request) {
        String ip = request.getHeader("x-forwarded-for");
        if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("PRoxy-Client-IP");
        }
        if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("WL-Proxy-Client-IP");
        }
        if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getRemoteAddr();
        }
        return ip;
    }
}
